<%@page import="java.util.HashMap"%>
<%@page import="org.firestorm.traficforecast.database.User"%>
<%@page import="org.firestorm.traficforecast.utils.Md5"%>
<%@page import="org.firestorm.traficforecast.utils.Constant"%>
<%@page import="org.firestorm.traficforecast.database.UserDAO"%>
<%@ page import="java.io.PrintWriter"%>
<%@ page import="org.json.simple.JSONObject"%>
<%@ page import="org.json.simple.JSONValue"%>
<%
	request.setCharacterEncoding("utf8");
	response.setContentType("application/json");
	PrintWriter outt = response.getWriter();
	JSONObject jsonObj = (JSONObject) JSONValue.parse(request
			.getParameter("para"));
	String username = jsonObj.get("user").toString();
	String password = Md5.Hash(jsonObj.get("pass").toString());
	User check = UserDAO.getUser(username, password);;
	JSONObject obj;
	if(check != null){
		HashMap<String, Boolean> tmp = new HashMap<String, Boolean>();
		tmp.put("res", false);
		obj = new JSONObject(tmp);
	}else{
		User newUser = new User(0, password, username);
		UserDAO.insertUser(newUser);
		session.setAttribute("user", newUser);
		HashMap<String, Boolean> tmp = new HashMap<String, Boolean>();
		tmp.put("res", true);
		obj = new JSONObject(tmp);
	}
	out.print(obj);
%>